#ifndef _EXTRA_H
#define	_EXTRA_H
#define ASIZE 100

#include "stdio.h"
#include "string.h"

char *RTstring;
char *lastRT;
char *lastDRT;
char *lastval;
char *storageX[ASIZE];
char *storageY[ASIZE];
char *ax[ASIZE];
char *ay[ASIZE];
int size=0;
int step=1;
int number=0;

void addNo(int i){
number = number * step;
number = number + i; 
step = step * 10;
}

void resetNo(){
number = 0;
step = 1;
}

void printNo(){
FILE *result;
result = fopen("result","a+");
fprintf(result,"%s%d\n", "(L:&INT) = ", number);
fclose(result);
resetNo();
}
void println(char * txt){
FILE *result;
result = fopen("result","a+");
fprintf(result,"%s\n", txt);
fclose(result);
}

void setLastVal(char * x)
{
lastval = x;
}

void setLastDRT(char * x)
{
lastDRT = x;
}

void setLastRT(char * x)
{
lastRT = x;
}

void storeDRT(char * name)
{
FILE *DRTcontainer;
DRTcontainer = fopen("container","a+");
fprintf(DRTcontainer,"%s", name);
fprintf(DRTcontainer,"%s"," = ");
fprintf(DRTcontainer,"%s",lastDRT); /*writes*/
fprintf(DRTcontainer,"%s"," = ");
fprintf(DRTcontainer,"%s\n",lastval);
fclose(DRTcontainer); /*done!*/
}

void start()
{
FILE *result;
  //Empty result file
  result = fopen("result","w+");
  fclose(result);
}

void clearDRT()
{
FILE *DRTcontainer;
DRTcontainer = fopen("container","w+");
fclose(DRTcontainer);
}

void copyContainer()
{
FILE *from, *to;
char ch; 
/* open source file */
  if((from = fopen("container", "r"))==NULL) {
    printf("Cannot open source file.\n");
  }

  /* open destination file */
  if((to = fopen("result", "a"))==NULL) {
    printf("Cannot open destination file.\n");
  }

  /* copy the file */
  while(!feof(from)) {
    ch = fgetc(from);
    if(ferror(from)) {
      printf("Error reading source file.\n");
    }
    if(!feof(from)) fputc(ch, to);
    if(ferror(to)) {
      printf("Error writing destination file.\n");

    }
  }

  if(fclose(from)==EOF) {
    printf("Error closing source file.\n");
  }

  if(fclose(to)==EOF) {
    printf("Error closing destination file.\n");
  }
}
void printRTfront(char * txt){
FILE *result;
result = fopen("result","a+");
fprintf(result,"%s", txt);
fclose(result);
}

void printRT(char * txt){
FILE *result;
result = fopen("result","a+");
fprintf(result,"%s%s\n", txt, RTstring);
fclose(result);
}

void RTback(char * txt){
RTstring = txt;
}
#endif
